<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<jsp:include page="./common/header.jsp"/>

<style type="text/css">
    body{background: url(static/image/4.jpg) no-repeat;background-size: cover;font-size: 16px;}
    .form{background: rgba(255,255,255,0.2);width:400px;margin:100px auto;}
    #login_form{display: block;}
    .fa{display: inline-block;top: 27px;left: 6px;position: relative;color: #ccc;}
    input[type="text"],input[type="password"]{padding-left:26px;}
    .checkbox{padding-left:21px;}
</style>

<body>
<div class="container">
    <div class="form row">
        <form class="form-horizontal col-sm-offset-3 col-md-offset-3" id="login_form" action="/user/login" method="get">
            <h3 class="form-title">Login to your account</h3>
            <div class="col-sm-9 col-md-9">
                <div class="form-group">
                    <i class="fa fa-user fa-lg"></i>
                    <input class="form-control required" type="text" placeholder="Username" name="name" autofocus="autofocus" maxlength="20"/>
                </div>
                <div class="form-group">
                    <i class="fa fa-lock fa-lg"></i>
                    <input class="form-control required" type="password" placeholder="Password" name="password" maxlength="8"/>
                </div>
                <div class="form-group">
                    <label class="checkbox">
                        <input type="checkbox" name="remember" value="1"/> Remember me
                    </label>
                    <hr />
                    <a href="/regist" id="register_btn" class="">Create an account</a>
                </div>
                <div class="form-group">
                    <input type="submit" class="btn btn-success pull-right" value="Login "/>
                </div>
            </div>
        </form>
    </div>
</div>
<script type="text/javascript" >
    $().ready(function() {
        $("#login_form").validate({
            rules: {
                username: "required",
                password: {
                    required: true,
                    minlength: 6
                },
            },
            messages: {
                username: "请输入姓名",
                password: {
                    required: "请输入密码",
                    minlength: jQuery.format("密码不能小于{0}个字 符")
                },
            }
        });

    $('#login_form').submit(function () {
        $(this).ajaxSubmit({
            dataType: "json",
            success: function (data) {
                if (data.code == '200') {
                    window.location.href = '/';
                } else {
                    $("#errdiv").css("display", "flex");
                    $("#message").html(data.message);
                }
            },
            error: function () {
                $("#errdiv").css("display", "flex");
                $("#message").html("操作失败，请联系管理员");
            }
        });
        return false;
    });
    });
</script>
</body>
</html>

